import java.io.File;
import java.io.IOException;

import tracer.Trace;
import visualizer.Visualize;
import webpage.Web;

public class MainClass {

	public static String workDir = new java.io.File("").getAbsolutePath()
			+ "/bin/";
	public static String config = workDir + "/kovida.xml";
	private static String ID = "testChecker";
	private static String graphVizCommand = "dot";

	
	public static void main(String[] args) {
		System.out.println("Started......");

		cleanOldFiles();
		
		Trace.start("Miniprojekt5Kovida", ID, workDir, true, config);
		
		int numberOfCreatedFiles = new Visualize(graphVizCommand).start(ID,
				workDir);

		String url = new Web(numberOfCreatedFiles,workDir,ID).getHtmlPage(); 
		
		try {
			Runtime.getRuntime().exec(
					"rundll32 url.dll,FileProtocolHandler " + url);
		} catch (IOException e) {
			e.printStackTrace();
		}

		System.out.println("Finished......with "+numberOfCreatedFiles+" created Files.");
	}




	private static void cleanOldFiles() {
		File dir = new File(workDir);
		for (File file : dir.listFiles()) {
			String filename = file.getName();
			if (filename.startsWith("kovida_") && filename.contains(ID)) {
				file.delete();
			}
		}
	}

}
